﻿@{
    ViewBag.Title = "FoodList";
    Layout = "~/Views/Shared/_Layout_List.cshtml";
}
<div class="main-container">
    <form method="get" id="Form" enctype="multipart/form-data">
        <div class="toolbar">
            <button class="btn" type="button" href="javascript:void(0);" onclick="AlertModelFrame('/System/FoodAdd', '添加新菜')"><i class="icon-plus"></i>&nbsp;添加</button>
            <button class="btn" type="button" id="btnDel"><i class="icon-minus"></i>&nbsp;删除</button>
        </div>
    </form>
    <div class="data-list">
        <table class="data-table display">
            <thead>
                <tr>
                    <th>
                        <input type="checkbox" id="selectAllChk" name="checkbox" />
                    </th>
                    <th>菜名</th>
                    <th>单价</th>
                    <th>折扣</th>
                    <th>菜分类</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (Food m in Model)
                {
                    <tr>
                        <td>
                            <input id="@m.ID" name="checkbox" type="checkbox" class="check" />
                        </td>
                        <td>@m.FoodName</td>
                        <td>@m.Price</td>
                        <td>
                            @if (m.Discount != 1)
                            {
                                @m.Discount
                            }
                        </td>
                        <td>@FoodType_Bll.GetData(m.TypeID).TypeName</td>
                        <td>
                            <a class="btn" href="javascript:void(0);" onclick="AlertModelFrame('/System/FoodEdit?Id=@m.ID','修改菜')"><i class="icon-edit"></i>&nbsp;编辑</a>
                            <a class="btn" href="javascript:void(0);" onclick="SingleDelete(@m.ID)"><i class="icon-trash"></i>&nbsp;删除</a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="data-pager">
        @Html.Pager("pageIndex", int.Parse(ViewData["pagesize"].ToString()), int.Parse(ViewData["TotalCount"].ToString()))
        @Html.PageSize("pageIndex", "pageSize", int.Parse(ViewData["TotalCount"].ToString()))
        <div style="clear: both"></div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        //全选
        $("#selectAllChk").click(function () {
            if ($(this).prop("checked")) {
                $(".check").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $(".check").each(function () {
                    $(this).removeAttr("checked");
                });
            }
        });
    });

    //删除，改变状态操作
    $('#btnDel').click(function () {
        var arrId = [];
        $(".check").each(function () {
            if ($(this).prop("checked")) {
                arrId.push($(this).attr('id'));
            }
        });
        var ids = arrId.join(',');
        if (ids == '') {
            //layer.alert('请选择要操作的项！', { icon: 5 });
            layer.msg('请选择要操作的项！', { icon: 5, time: 1000, shade: 0.3 });
        }
        else {
            SingleDelete(ids);
        }
    });

    function SingleDelete(id) {
        layer.confirm('确认删除记录？', { icon: 3, title: '提示' }, function () {
            var url = "/System/DelFood?ids=" + id;
            $.ajax({
                type: "POST",
                url: url,
                data: "",
                success: function (msg) {
                    if (msg.Status) {
                        layer.msg('删除成功', { icon: 6, time: 700, shade: 0.3 }, function () { window.location.reload(true); });
                    } else {
                        layer.msg('删除失败', { icon: 5, time: 700, shade: 0.3 }, function () { window.location.reload(true); });
                    }
                }
            });
        });
    }
</script>
